package TUILayer;
import java.util.Scanner;
import ControlLayer.LendCtr;

/**
 * Write a description of class LendUI here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LendUI
{
    private LendCtr lendCtr;//Lend UI must know the Loan controller

    public LendUI()
    {
       lendCtr = new LendCtr();
    }
    
    public void start(LendCtr ctr)
    {
     lendCtr= ctr;
     lendMenu();
    }
    
    public void lendMenu()
    {
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choise = writeLendMenu();
            if (choise == 1){
                findLend();
            }
            else { 
                if(choise == 2){
                    createLend();
                }
                else{
                    if(choise == 3){
                        exit = true;
                    }
                }
            }
        }
    }
    
    private int writeLendMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println(" *** Lend Menu ***");
            System.out.println(" (1) find lend information");
            System.out.println(" (2) Create Loan description");

            System.out.print("\n Make your choise: ");
            
            int choise = keyboard.nextInt();
            return choise;
    }
    
    private int inputLendNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type Lend number: ");
        int lendId = keyboard.nextInt();
        return lendId;
    }
    
    private int inputPersonNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type Lend Person number: " );
        int personId = keyboard.nextInt();
        return personId;
    }
    private String inputDate()
    {
         // creates an object keyboard to read data from the keyboard
         Scanner keyboard = new Scanner(System.in);
         System.out.println("Type copy releaseDate: " );
         String date = keyboard.nextLine();
         return date;
    }
    public void findLend()
    {
        int lendId = inputLendNo();
        int personId = inputPersonNo();
        if(lendCtr == null){
        }
        else {
            if( lendCtr.getClass() != null){
            }
            else {
                if(lendCtr.findLend(personId, lendId)!= null){
                
                }
                else {
                System.out.println("Loan id: "+lendCtr.findLend(personId, lendId));
                }
            }
        }
    }
    
    public void createLend()
    {
        int personId = inputPersonNo();
        int lendId = inputLendNo();
        String date = "";
        
        if(lendCtr == null){
        }
        else{
            if(lendCtr.CreateLend(personId, lendId, date) != null){
                lendCtr.CreateLend(personId, lendId, date);
                System.out.println("Loan: "+lendCtr.findLend(personId, lendId).getId());
            }
            else {
                
            }
        }
        }
    }
